package com.twinkle.rpc.client.nettyConfig.nettyInitializer;


import com.twinkle.rpc.client.nettyConfig.handler.NettyClientHandler;
import com.twinkle.rpc.common.serializer.mycoder.MyDecoder;
import com.twinkle.rpc.common.serializer.mycoder.MyEncoder;
import com.twinkle.rpc.common.serializer.myserializer.JsonSerializer;
import com.twinkle.rpc.common.serializer.myserializer.ObjectSerializer;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * @author twinkle
 * netty的pipeline，所有的数据的处理方式都添加到pipeline中
 * @version 1.0
 */
public class NettyClientInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //使用自定义的编解码器
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new MyDecoder());
        pipeline.addLast(new MyEncoder(new JsonSerializer()));
        pipeline.addLast(new NettyClientHandler());
    }
}
